package com.eyas.business.controllor.appointmentinfo;

import com.eyas.business.model.jdbcEntity.table.ChildrenInfo;
import com.eyas.business.model.pojo.appointmentinfo.QueryParamDTO;
import com.eyas.business.model.pojo.appointmentinfo.QueryResultDTO;
import com.eyas.business.model.pojo.appointmentinfo.YKParamDTO;
import com.eyas.business.service.appointmentinfo.AppointmentInfoService;
import com.eyas.business.service.userinfo.UserInfoService;
import com.eyas.core.model.page.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @Auther: 王龙龙
 * @Date: 2019/3/16 17:18
 * @Description:
 */
@Controller
@RequestMapping("/eyas/appointmentinfo/")
public class AppointmentInfoAction {
    @Autowired
    private AppointmentInfoService appointmentInfoService;
    @Autowired
    private UserInfoService userInfoService;

    @GetMapping("/queryAppointmentInfo")
    @ResponseBody
    public PageResult<QueryResultDTO> queryAppointmentInfo(QueryParamDTO dto,
                                                           @RequestParam(defaultValue = "1") int page,
                                                           @RequestParam(defaultValue = "10") int limit) {
        PageResult<QueryResultDTO> result = this.appointmentInfoService.queryAppointmentInfo(dto,page-1,limit);
        return result;
    }

    @GetMapping("/queryAppointmentStatus")
    @ResponseBody
    public PageResult<QueryResultDTO> queryAppointmentStatus(QueryParamDTO dto,
                                               @RequestParam(defaultValue = "1") int page,
                                               @RequestParam(defaultValue = "10") int limit) {
        PageResult<QueryResultDTO> result = this.appointmentInfoService.queryAppointmentStatus(dto,page-1,limit);
        return result;
    }


    @GetMapping("/edit")
    private String edit(Integer userid, Model model) {
        model.addAttribute("userid",userid);
        List<ChildrenInfo> list = userInfoService.queryChildrenInfoByUser(userid);
        model.addAttribute("childrens",list);
        return "/appointmentinfo/edit";
    }

    @PostMapping("/saveAppointmentInfo")
    @ResponseBody
    public String saveAppointmentInfo(YKParamDTO ykParamDTO, HttpSession session) {
        this.appointmentInfoService.saveAppointmentInfo(ykParamDTO,session);
        return "{\"success\":true}";
    }

    @GetMapping("/edit2")
    public String edit2(Integer appointmentid, Model model) {
        model.addAttribute("appointmentid",appointmentid);
        return "/appointmentinfo/edit2";
    }

    @PostMapping("/updateAppointmentInfo")
    @ResponseBody
    public String updateAppointmentInfo(QueryParamDTO dto,HttpSession session) {
        this.appointmentInfoService.updateAppointmentInfo(dto,session);
        return "{\"success\":true}";
    }
}
